package com.jinjie.config.tomcat;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @program: com.jinjie.config.tomcat
 * @Description:
 * @author: Administrator
 * @create: 2025-01-21 11:28
 **/
@Configuration
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
public class TomcatConfiguration implements  WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
    /**
     * Customize the specified {@link WebServerFactory}.
     *
     * @param factory the web server factory to customize
     */
    @Override
    public void customize(TomcatServletWebServerFactory factory) {
        // 隐藏 Tomcat 的 Server 信息
        log.info(" = =================== TomcatConfiguration");
        factory.addConnectorCustomizers(connector -> connector.setProperty("server", ""));
        factory.addConnectorCustomizers(connector ->  connector.setAttribute("showServerInfo", false));

    }

}
